#include "nntpclient.h"

#include <QtCore>

#include "nntpwireclient.h"
#include "connectionmanager.h"

class NNTPClientPrivate
{
public:
    NNTPClientPrivate(NNTPClient *qq);

    // Connections
    QList<NNTPWireClient *> connections;
    ConnectionManager *connectionManager;

    NNTPClient *q;
};

NNTPClientPrivate::NNTPClientPrivate(NNTPClient *qq) :
        q(qq)
{
    connectionManager = new ConnectionManager;
}

NNTPClient::NNTPClient(QObject *parent) :
    QObject(parent), d(new NNTPClientPrivate(this))
{

}

NNTPClient::~NNTPClient()
{
}

void NNTPClient::start()
{
    NNTPWireClient *client = new NNTPWireClient(this);
    //connect(client, SIGNAL(connectedToNNTPServer()), this, SLOT(clientConnected()));
    d->connectionManager->addConnection(client);
    d->connections << client;
    client->start(QThread::LowestPriority);
    client->connectToServer(serverInformation->adres, serverInformation->port);
    client->getCapabilities();
    client->closeConnection();
}

void NNTPClient::stop()
{
    foreach(NNTPWireClient *client, d->connections) {
        //client->quit();
    }
}

void NNTPClient::setServerInformation(ServerInformation *info)
{
    serverInformation = info;
}

void NNTPClient::clientConnected()
{
    NNTPWireClient *client = static_cast<NNTPWireClient *>(sender());
    qDebug() << client << " Connected";
    //client->authenticate();
    //client->getCapabilities();
}

void NNTPClient::getCapabilities()
{
    //d->connections.at(0)->getCapabilities();
}
